import { cloneDeep } from 'lodash';
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    transFilterObj: {
      timeFlag: 0,
      lang: 'zh-CN',

      productid: null,
      productname: null,
      registertime: null,
      authorized: false,
      watchshow: 0,

      platform: [],
      platformFull: [],

      selectedDate: [],
      qualitySelectedDate: [],
      conditions: {
        partner: [],
        usergroup: [],
        version: [],
        newUserGroup: [],
      },
    },
    developerObj: {
      developerid: null,
      email: null,
    },
    productList: [],
    productOwnList: [],
    productObj: {
      authorized: false,
      authorizedpage: '',
      sequencenumber: {},
    },

    loadingState: 'loading',
    loadingText: '',

    plusState: {
      productid: null,
      isPlus: false
    },
    plusInfo: {
      kvInfo: { eventLimit: 0, keyLimit: 0, valueLimit: 0 },
      exploreEventConfigure: { exploreUserCount: 0, keepUserCount: 0, uerCount: 0, calculateCount: 0 },
      reportConfigure: { reportCount: 0, reportUsedCount: 0 },
      logReportInfo: { startTime: '2021-01-01 00:00:00', endTime: '2021-01-01 00:00:00', status: 3 },
    },
  },
  mutations: {
    setTransFilterObj(state, paramObj) {
      Object.assign(state.transFilterObj, paramObj);
    },
    setLoadingState(state, paramObj) {
      state.loadingState = paramObj;
    },
    setLoadingText(state, paramObj) {
      state.loadingText = paramObj;
    },
    setProductList(state, paramObj) {
      state.productList = cloneDeep(paramObj);
      state.productOwnList = paramObj.filter(item => {
        return !item.authorized;
      });
    },
    setDeveloperObj(state, paramObj) {
      Object.assign(state.developerObj, paramObj);
    },
    setProductObj(state, paramObj) {
      Object.assign(state.productObj, paramObj);
    },
    setPlusState(state, paramObj) {
      Object.assign(state.plusState, paramObj);
    },
    setPlusInfo(state, paramObj) {
      Object.assign(state.plusInfo, paramObj);
    },
    setPlusFree(state, paramObj) {
      Object.assign(state.plusInfo.exploreEventConfigure, paramObj.exploreEventConfigure);
      Object.assign(state.plusInfo.reportConfigure, paramObj.reportConfigure);
    },
  },
  actions: {
  },
  modules: {
  }
});
